<?php
require '../../include/library.inc.php';
require '../../include/admin_login.inc.php';
require 'paging.inc.php';


$sql = "SELECT
				task_id,
				title,
				priority,
				status,
				by_user,
				creation_time
			FROM
				tasks  t
			WHERE
				
				NOT EXISTS (SELECT null FROM  law_users  l  WHERE  l.use_id = t.by_user)
				
				AND 
				
				EXISTS (SELECT null FROM  users  u  WHERE  u.user_id = t.by_user AND published)
				
				
				
		";

if (!isset($_GET['sort'])) $_GET['sort'] = 1;
if (!isset($_GET['sortBy'])) $_GET['sortBy'] = 6;

$paging = new Paging($sql, $_GET['sortBy'], $_GET['sort'], array(6=>"Подредба"), 50);
$result = $paging->query();
	
	head_admin("Клиенти");
?>
		
			<?php if ($_SESSION['message']) { ?>
			<div class="message green">
				<?=$_SESSION['message']?>
			</div>
			<?php unset($_SESSION['message']); } ?>
		
		
           
            <h3>Тези (<?=$paging->count()?>) кореспонденции не са свързани с юристи</h3>
            
            <table id="listing" width="100%" cellpadding="0" cellspacing="0">
			<thead>
				<tr>
					<td>Тема</td>
					<td>Потребител</td>
                    <td>От дата</td>
                    <td>Приоритет</td>
                    <td>Достъп</td>
                    
				</tr>
			</thead>
			<tbody>
			<?php
			  
			  $i=1;
			  while ($row = mysql_fetch_object($result)) {				  
			?>
					<tr class="<?=(($i%2)?"none":"zebra")?>">
                    
                    	<td>
                        <?=$row->title?>
                        </td>
					
						<td><a href="user_edit.php?user_id=<?=$row->by_user?>" title="Редактирай"><?=get_user_name($row->by_user)?></a></td>
						<td><?=date('d M Y h:m', strtotime($row->creation_time))?></td>
                        
						<td class="icons">
							<?php if($row->priority) echo 'Спешно';?>
							
						</td>
                        
                        <td class="switch">
							
							 <a href="user_admin.php?user_id=<?=$row->by_user?>&publish=0" class="turn_on" name="turn_on" title="Спри достъп"></a>
							
						</td>
						
					</tr>
         <?php
              $i++;    
            } 
         ?>				  
			</tbody>
		</table>
        
        <div class="pagingwrap"><div class="paging">
			<?=$paging->display()?>
		</div></div>
            
<?php
	foot_admin(); 
?>